package com.tianci.appstore.ui.list.bootsetting;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.tianci.appstore.LaunchManageActivity;
import com.tianci.appstore.R;
import com.tianci.appstore.ui.data.SkyAppBaseData;
import com.tianci.appstore.ui.data.SkyListAppData.ListType;
import com.tianci.appstore.ui.list.ListBlock;
import com.tianci.appstore.utils.SkyConstants;

/**
 * 列表页中的app块View 使用此view的列表有：1.我的应用列表、2.卸载应用列表、3.清理缓存列表、4.应用转移列表
 * 其中1的supportMultiSel为false，而234的为true
 **/
public class LauncherItem extends ListBlock {
    private TextView mTips = null;

    public LauncherItem(Context context) {
        super(context, null);
        addTips();
    }

    @Override
    protected void createView() {
        super.createView();
    }

    private void addTips() {
        mTips = new TextView(mContext);
        mTips.setTextColor(Color.WHITE);
        mTips.setTextSize(SkyConstants.Dpi(35));
        mTips.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.launch_on_boot_arrow, 0);
        mTips.setCompoundDrawablePadding(SkyConstants.Div(10));
        mTips.setGravity(Gravity.CENTER);
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER | Gravity.RIGHT);
        params.rightMargin = SkyConstants.Div(22);
        mTips.setText(getResources().getString(R.string.launch_on_boot_no_set) + "                                        "
                + getResources().getString(R.string.launch_on_boot_change));
        addView(mTips, params);
    }

    @Override
    public void update(SkyAppBaseData data) {
        mTips.setText(getResources().getString(R.string.launch_on_boot_change));
        if (data.getTitle() != null && !data.getTitle().equals("")) {
            iconImage.setVisibility(View.VISIBLE);
            titleText.setVisibility(View.VISIBLE);
            super.update(data);
        } else {
            iconImage.setVisibility(View.GONE);
            titleText.setVisibility(View.GONE);
            mTips.setText(getResources().getString(R.string.launch_on_boot_no_set) + "                                        "
                    + getResources().getString(R.string.launch_on_boot_change));
        }
    }

    public void setSelectMode(boolean selMode) {
        inSelectionMode = selMode;
    }


    @Override
    public void onClick(View v) {
        Intent intent = new Intent();
        intent.setClass(mContext, LaunchManageActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra("listType", ListType.SELECTED_LAUNCH_LIST.toString());
        mContext.startActivity(intent);
    }

    @Override
    public void onFocusChange(View arg0, boolean hasFocus) {
        // TODO Auto-generated method stub

    }

    @Override
    public void destory() {
        iconImage.setImageBitmap(null);
        if (cornerImage != null) {
            cornerImage.setImageBitmap(null);
        }

    }
}
